import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:"",
    user_id:"",
    allNum:0,
    cartData:[],
  },
  mutations: {
    add(state,token){
      state.token=token
      state.user_id=token.user_id
    //  console.log(stete.user);
    },
    tui(state){
      state.token=""
    },
    getUser (state) {
      return state.user
    },
    setCartData(state,data){
		  state.allNum = 0
		  data.forEach(item=>{
			  item.money = item.num*item.price
			  item.visible = false
			  state.allNum += item.num
		  })
		  state.cartData = data
	  },
    
    
  },
  actions: {
  },
  modules: {
  },
  plugins: [createPersistedState()]
})
